﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using University.Workshop.Business;

namespace University.Workshop.Presenters
{
    public class PresenterRegisterExpense
    {
        IRegisterExpenseView view;
        Model.Expense expenseToRegister = new Model.Expense();

        public PresenterRegisterExpense(IRegisterExpenseView view, Model.User user)
        {
            this.view = view;
            //this.expenseToRegister.Description = user.Login != null ? user.Login : string.Empty;
            //this.expenseToRegister.Receipt = user.Password != null ? user.Password : string.Empty;
            //Agregar el login+
            //Agregar al usuario como true
            this.expenseToRegister.UserId = user.UserId;
        }

        public void UpdateViewData()
        {
            //view...Login = expenseToRegister.Login;
        }

        public bool RegisterExpense()
        {
            try
            {
                Model.Expense e = new Model.Expense() { UserId = expenseToRegister.UserId, SpendDate = view.SpendDate, Price=view.Price, ExpenseType=view.Item, Amount=view.Amount, Description=view.Description, Receipt=view.Receipt};
                ManagerExpense.VerifyDataExpense(e);
                ManagerExpense.NewExpense(e);
                return true;
            }
            catch (Exception ex)
            {
                view.ErrorMessage(string.Format(ex.Message, "Registar Gasto"));
                return false;
            }



        }
    }
}
